package me.zhengjie.modules.system.rest;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import me.zhengjie.annotation.Log;
import me.zhengjie.modules.system.domain.Teachaudit;
import me.zhengjie.modules.system.service.TeachauditService;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequiredArgsConstructor
@Api(tags = "教材审核管理")
@RequestMapping("/api/teachaudit")
public class TeachauditController {

    private final TeachauditService teachauditService;

    @PostMapping
    @Log("新增教材审核")
    @ApiOperation("新增教材审核")
    public ResponseEntity<Object> createTeachandteacher(@Validated @RequestBody Teachaudit resources){
        teachauditService.create(resources);
        return new ResponseEntity<>(HttpStatus.CREATED);
    }

    @PutMapping
    @Log("新增教材审核")
    @ApiOperation("新增教材审核")
    public ResponseEntity<Object> updateTeachandteacher(@Validated @RequestBody Teachaudit resources){
        teachauditService.update(resources);
        return new ResponseEntity<>(HttpStatus.CREATED);
    }

    @GetMapping("/getTeachAudit")
    public ResponseEntity<Teachaudit> getTeachAudit(@Validated @RequestParam(value = "id",required = false) String id){

        QueryWrapper queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("teachId",id);
        return new ResponseEntity<>(teachauditService.getOne(queryWrapper),HttpStatus.OK);
    }
}
